package com.salton123.soulove.biz_bmob.aty

import android.os.Bundle
import android.view.View
import com.alibaba.android.arouter.facade.annotation.Route
import com.salton123.soulove.biz_bmob.helper.BmobHelper
import com.salton123.soulove.biz_bmob.R
import com.salton123.soulove.common.Constants
import com.salton123.ui.base.BaseActivity
import kotlinx.android.synthetic.main.login_register.*

/**
 * @Time:2021/2/3 15:51
 * @Author:wujinsheng
 * @Description:
 */
@Route(path = Constants.Router.Bmob.REGISTER)
class RegisterAcitivity : BaseActivity() {
    override fun initViewAndData(savedInstanceState: Bundle?) {
        setListener(btnRegister)
    }

    override fun getLayoutId(): Int = R.layout.login_register

    override fun onClick(v: View?) {
        super.onClick(v)
        when (v) {
            btnRegister -> {
                val etUserName = etUserName.text.toString()
                val etPassword = etPassword.text.toString()
                val etPasswordRepeat = etPasswordRepeat.text.toString()
                if (etPasswordRepeat != etPassword) {
                    shortToast("前后两次密码不相同")
                    return
                }
                val etMail = etMail.text.toString()
                BmobHelper.register(etUserName, etPassword, etMail).subscribe({
                    shortToast("注册成功")
                }, { tx ->
                    longToast("注册失败:${tx.printStackTrace()}")
                })
            }
        }
    }
}